package demo.controller;

import demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 演示在控制器中调用业务逻辑类：accountService
 * 注解@Autowired此处作用为将@Service修饰的AccountService类通过容器自动导入（AOP）
 */
@RestController
public class ControllerForAccountService {
    /*变量注入方式，不推荐（标黄）
    @Autowired
    AccountService accountService;
    */

    //推荐间接构造，例如利用构造器或set方法：
    final AccountService accountService;

    @Autowired
    public ControllerForAccountService(AccountService accountService) {
        this.accountService = accountService;
    }

    @RequestMapping("/getAccountByID/{id}")
    public HashMap getAccountByID(@PathVariable String id){
        return accountService.getAccountByID(id);
    }

}
